﻿using System;
using ConfigService;
using EmailService;
using LogService;
using Microsoft.Extensions.DependencyInjection; // 引入服务注册依赖

namespace ICO2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            TestICO2();

        }


        /// <summary>
        /// 服务注册演示  也可以添加拓展方法中处理
        /// </summary>
        private static void TestICO2()
        {
            IServiceCollection services = new ServiceCollection();
            //在创建 BuildServiceProvider 之前要注入服务依赖
            // services.AddScoped<ILogService, ConsoleLogImp>(); // 注入日志服务
            services.AddLogService(); //此方法和上面一毛一样 ，只是把操作封装到了 拓展方法中了。

            //  services.AddScoped(typeof(IConfigService), a => new IniFileConfigService("a.txt"));
            services.AddLayeredConfig("a.txt");

            services.AddScoped<IEmailService, EmailServiceImp>();

            using (ServiceProvider sp = services.BuildServiceProvider())
            {
                ILogService log = sp.GetRequiredService<ILogService>();
                IEmailService emailSer = sp.GetRequiredService<IEmailService>();
                IConfigService configServer = sp.GetRequiredService<IConfigService>();
                #region 添加一些测试信息
                if (!configServer.ExistFileName())
                {
                    configServer.AddOREditKeyValue("name", "wangtian");
                    configServer.AddOREditKeyValue("pwd", "123");
                    configServer.SaveAll();
                }

                #endregion

                log.Log(LogLeve.Info, "开始发送邮件");
                //emailSer.SendEamil("w", "z", "巴拉巴拉巴");

                emailSer.LoadSenderInfo();
                emailSer.SendEamil("z", "巴拉巴拉巴");
                log.Log(LogLeve.Info, "发送完成.");
            }

        }
    }
}
